const md5 = require('md5')
module.exports = options => {
    return async function auth(ctx,next) {
        if(ctx.request.url.indexOf('/user/login')!==-1 || ctx.request.url.indexOf('/login/restList') !== -1){
           await next();
        }else{
            const uuid = ctx.request.headers['uuid'];
            const timestamp = ctx.request.headers['timestamp'];
            const authorization = ctx.request.headers['authorization'];
            const method = ctx.request.method;
            const localtoken = md5(method+'&'+uuid+timestamp+md5(options.seed));
            if(localtoken === authorization){
              await next()
            }else{
                ctx.code = 401;
            }
        }
 

    }
}